<?php

namespace App\Trip\Plane\Requests;

use Carbon\Carbon;
use Illuminate\Http\Request;

class PriceCalendarRequest implements CommonQueryInterface
{
    use TraitFromToDateRequest;

    private Request|array $req;

    /**
     *
     */
    public function __construct(Request|array $request)
    {
        $this->req = $request;

    }

    public function getEndDate(): string
    {
        $trip_date = $this->getStartDate();
        // 30天的限制
        return Carbon::parse($trip_date)->addDays(30)->toDateString();
    }

    public function getStartDate(): string
    {
        $trip_date = $this->getTripDate();
        $today     = Carbon::today()->toDateString();
        if (Carbon::parse($trip_date)->lessThan(Carbon::today())) {
            return $today;
        }

        // 如果出发时间超过一个月 取 出发时间 前后14天
        if (Carbon::parse($trip_date)->diffInDays(Carbon::today()) > 30) {
            return Carbon::parse($trip_date)->subDays(15);
        }

        return Carbon::today()->toDateString();
    }


}